package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Food;
import com.neusoft.elmboot.service.FoodService;

@RestController
@RequestMapping("/Foods")
public class FoodController {

	@Autowired
	private FoodService foodService;
	
	@GetMapping("/businessId/{businessId}")
	public List<Food> listFoodByBusinessId(Food food) throws Exception{
		return foodService.listFoodByBusinessId(food.getBusinessId());
	}
	
	@GetMapping("/foods/foodId/{foodId}")
	public Food getFoodById(Food food) throws Exception{
		return foodService.getFoodById(food.getFoodId());
	}
	
	@PostMapping("/name/{foodName}/explain/{foodExplain}/price/{foodPrice}/img/{foodImg}/businessId/{businessId}/remarks/{remarks}/quantity/{foodQuantity}")
	public int createFood(Food food) throws Exception{
		String img1 = food.getFoodImg().replace("-", "/").replace("_", "+").replace("~", ";");
		food.setFoodImg(img1);
		return foodService.createFood(food);
	}
	
	@DeleteMapping("/foodId/{foodId}/businessId/{businessId}")
	public int removeFood(Food food) throws Exception{
		return foodService.removeFood(food);
	}
	
	@PutMapping("foodId/{foodId}/name/{foodName}/explain/{foodExplain}/price/{foodPrice}/img/{foodImg}/remarks/{remarks}/quantity/{foodQuantity}")
	public int updateFood(Food food) throws Exception{
		String img1 = food.getFoodImg().replace("-", "/").replace("_", "+").replace("~", ";");
		food.setFoodImg(img1);
		return foodService.updateFood(food);
	}
}
